<%@ page language="java" import="java.util.*,java.sql.*" pageEncoding="utf-8"%>
<%
String path = request.getContextPath();
String basePath = request.getScheme()+"://"+request.getServerName()+":"+request.getServerPort()+path+"/";
%>
<jsp:useBean id="db" class="connBean.ConnDB" scope="page">
</jsp:useBean>
<%@ include file="Logined.jsp" %>
<link href="images/skin.css" rel="stylesheet" type="text/css" />
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" /><style type="text/css">
    <!--
body {
	margin-left: 0px;
	margin-top: 0px;
	margin-right: 0px;
	margin-bottom: 0px;
	background-color: #EEF2FB;
    font-size:20px;
}
-->
  <head>

.tab_content{
border-right:1px dashed #cccccc;
font-size:20px;
}
.tab_title{
color:#444444;
font-size:20px;
font-weight:bold;
text-align:center;
}
</style>



<body>
<table width="100%"  height="97%"border="0" cellpadding="0" cellspacing="0">
  <tr>
    <td width="17" height="35" valign="top" background="images/mail_leftbg.gif"><img src="images/left-top-right.gif" width="17" height="29" /></td>
    <td valign="top" background="images/content-bg.gif"><table width="100%" height="31" border="0" cellpadding="0" cellspacing="0" class="left_topbg" id="table2">
      <tr>
        <td height="31"><div class="titlebt">查询商品</div></td>
      </tr>
    </table></td>
    <td width="16" valign="top" background="images/mail_rightbg.gif"><img src="images/nav-right-bg.gif" width="16" height="29" /></td>
  </tr>
  <tr>
    <td height="149" valign="middle" background="images/mail_leftbg.gif">&nbsp;</td>
    <td valign="top" height="100%" bgcolor="#F7F8F9">
    <%request.setCharacterEncoding("utf-8");
String mainkey=request.getParameter("mainkey");
System.out.println(mainkey);
int secondtype=Integer.parseInt(request.getParameter("second_type"));
System.out.println(secondtype);
int price1=Integer.parseInt(request.getParameter("price_1"));
int price2=Integer.parseInt(request.getParameter("price_2"));
System.out.println(price1);
System.out.println(price2); %>




    <FORM METHOD=POST ACTION="deleteallProduct.jsp">
     <table width="100%">
       <tr>
         <td width="70"><input type="checkbox" id="selAll" onclick="selectAll();" />全选 
<input type="checkbox" id="inverse" onclick="inverse();" />反选 <input type="submit" value="删除"/></td>
         <td>商品编号</td>
         <td>商品名称</td>
         <td>商品类别</td>
         <td>商品信息</td>
         <td>商品价格</td>
         <td>商品数量</td>
         <td>商品图片</td>
         <td>时间</td>
         <td>状态</td>
         <td>编辑</td>
       </tr>
   				<%
				  db.OpenConn();
				  db.createStmt();
				  String searchsql;
				  if(secondtype!=0&&mainkey!=""){
				  searchsql="select p.p_id,p.p_name,s.st_name,p.p_price,p.p_quantity,p.p_image,p.p_description,p.p_time,p.p_status from product as p left join second_type as s on p.st_id=s.st_id where p.p_price between "+price1+" and "+price2+" and (p.p_name like '%"+mainkey+"%' or p.p_description like '%"+mainkey+"%' or p.st_id="+secondtype+")";
				  }else if(secondtype==0&&mainkey!=""){
				  searchsql="select p.p_id,p.p_name,s.st_name,p.p_price,p.p_quantity,p.p_image,p.p_description,p.p_time,p.p_status from product as p left join second_type as s on p.st_id=s.st_id where p.p_price between "+price1+" and "+price2+" and (p.p_name like '%"+mainkey+"%' or p.p_description like '%"+mainkey+"%')";
				  }else if(secondtype!=0&&mainkey==""){
				  searchsql="select p.p_id,p.p_name,s.st_name,p.p_price,p.p_quantity,p.p_image,p.p_description,p.p_time,p.p_status from product as p left join second_type as s on p.st_id=s.st_id where p.p_price between "+price1+" and "+price2+" and p.st_id="+secondtype;
				  }else{
				  searchsql="select p.p_id,p.p_name,s.st_name,p.p_price,p.p_quantity,p.p_image,p.p_description,p.p_time,p.p_status from product as p left join second_type as s on p.st_id=s.st_id where p.p_price between "+price1+" and "+price2;
				  }
				  System.out.println(searchsql);
				  ResultSet searchP=db.Query(searchsql);
				  int count=0;
				  while(searchP.next())
				  {count++;
				  String p_id=searchP.getString("p_id");
				   %>
        <tr>
           <td>
          <input type="checkbox" name="checkAll" id="checkAll" onclick="setSelectAll();" value="<%=searchP.getString("p_id") %>"/>
          </td>
          <td class="tab_content">
           <%=searchP.getString("p_id") %>
          </td>
          <td class="tab_content">
            <%=searchP.getString("p_name") %>
          </td>
          <td class="tab_content">
            <%=searchP.getString("st_name") %>
          </td>
          <td class="tab_content">
            <%
            String content = searchP.getString("p_description");
            String subcontent = "";
            if (content.length() >= 15)
            {subcontent = content.substring(0, 14);}
            else
            {subcontent = content;}
            out.println(subcontent); %>
          </td>
          <td class="tab_content">
          <%=searchP.getString("p_price") %>
          </td>
          <td class="tab_content">
          <%=searchP.getString("p_quantity") %>
          </td>
          <td class="tab_content">
          <% 
          String image=searchP.getString("p_image");
                  String a[] = image.split(";"); 

          %>
          
          
          
          <img src="images/<%=a[0]%>" width=80 height=80/>
          </td>
          <td class="tab_content">
          <%String p_time=searchP.getString("p_time");
            String substr=p_time.substring(0,10);
           %>
            <%=substr %>
          </td>
          
          <td>
          			<%
			int status=searchP.getInt("p_status");
			String statusname="";
			switch(status){
			case 0:statusname="新品";break;
			case 1:statusname="非新品";break;
			case 2:statusname="特价";break;
			case 3:statusname="下架";break;
			case 4:statusname="缺货";break;
			}			
			%>
            <%=statusname%>
          
          </td>
          
          <td>
          <a href="productdetail.jsp?selectid=<%=p_id %>">修改</a>
          <a href="deleteProduct.jsp?deleteid=<%=p_id %>">删除</a>
          </td>
        </tr>
			    	<%}if(count==0){ %>

			    	<tr><td colspan=10>没有搜索到您想要的商品！</td></tr>

			    	<%} %>
 
     </table>
  </FORM>


    























</td>
    <td background="images/mail_rightbg.gif">&nbsp;</td>
  </tr>
  <tr>
    <td valign="bottom" background="images/mail_leftbg.gif"><img src="images/buttom_left2.gif" width="17" height="17" /></td>
    <td background="images/buttom_bgs.gif"><img src="images/buttom_bgs.gif" width="17" height="17"></td>
    <td valign="bottom" background="images/mail_rightbg.gif"><img src="images/buttom_right2.gif" width="16" height="17" /></td>
  </tr>
</table>
</body>
<script language="javascript"> 

//选中全选按钮，下面的checkbox全部选中 
var selAll = document.getElementById("selAll"); 
function selectAll() 
{ 
  var obj = document.getElementsByName("checkAll"); 
  if(document.getElementById("selAll").checked == false) 
  { 
  for(var i=0; i<obj.length; i++) 
  { 
    obj[i].checked=false; 
  } 
  }else 
  { 
  for(var i=0; i<obj.length; i++) 
  {   
    obj[i].checked=true; 
  } 
  } 
  
} 

//当选中所有的时候，全选按钮会勾上 
function setSelectAll() 
{ 
var obj=document.getElementsByName("checkAll"); 
var count = obj.length; 
var selectCount = 0; 

for(var i = 0; i < count; i++) 
{ 
if(obj[i].checked == true) 
{ 
selectCount++; 
} 
} 
if(count == selectCount) 
{ 
document.all.selAll.checked = true; 
} 
else 
{ 
document.all.selAll.checked = false; 
} 
} 

//反选按钮 
function inverse() { 
var checkboxs=document.getElementsByName("checkbox"); 
for (var i=0;i<checkboxs.length;i++) { 
  var e=checkboxs[i]; 
  e.checked=!e.checked; 
  //setSelectAll(); 
} 
} 

</script> 

